package com.example.album;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AdminHandler {

    @Autowired
    private AdminService adminService;

    @PostMapping("addcategory")
    @ResponseBody
    public Map<String, Object> addCategory(@RequestBody Map<String, String> req) {
        String categoryName = req.get("categoryname");
        Map<String, Object> result = new HashMap<>();
        result=adminService.addCategory(categoryName);
        return result;
    }

    @PostMapping("deletecategory")
    @ResponseBody
    public Map<String, Object> deleteCategory(@RequestBody Map<String, String> req) {
        System.out.println("deleteCategory called with categoryName: " + req.get("categoryname"));
        String categoryName = req.get("categoryname");
        Map<String, Object> result = new HashMap<>();
        result = adminService.deleteCategory(categoryName);
        return result;
    }

    @PostMapping("banuser")
    @ResponseBody
    public Map<String, Object> banUser(@RequestBody Map<String, String> req) {
        String userId = req.get("userId");
        Map<String, Object> result = new HashMap<>();
        result = adminService.banUser(userId);
        return result;
    }

    @PostMapping("unbanuser")
    @ResponseBody
    public Map<String, Object> unbanUser(@RequestBody Map<String, String> req) {
        String userId = req.get("userId");
        Map<String, Object> result = new HashMap<>();
        result = adminService.unbanUser(userId);
        return result;
    }
}
